home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swags_z.zip / SCREEN.SWG / 0067_Screen Saver w-mouse.pas < prev    next >
Pascal/Delphi Source File  |  1994-05-26  |  12KB  |  311 lines

  1. {
  2. Here is my unit for a screen saver - totally self contained with mouse support
  3. as well (Moving the mouse will reset the screensaver time delay as well, and
  4. placing the mouse in top right corner will blank the screen!)
  5. }
  6. unit blanker;
  7.  
  8. interface
  9.  
  10. const
  11. blank_screen     : boolean=true;            {True=blank the screen.         }
  12. blank_screen_now : boolean=false;           {True=blank screen immediately. }
  13. count            : integer = 0;             {To keep track of our calls.    }
  14. screen_cond      : boolean=false;           {True=screen is blanked.        }
  15.  
  16. var
  17.  rows,columns:byte;
  18.  
  19. function mouseinbox(x1,y1,x2,y2,butt:word):boolean;
  20.  
  21. implementation
  22.  
  23. uses dos;
  24.  
  25. var
  26.  OldInt9       : Procedure;
  27.  OldInt1c      : pointer;
  28.  ExitSave      : pointer;
  29.  r             : Registers;
  30.  loop          : byte;
  31.  x             : array[1..30] of byte;
  32.  y             : array[1..30] of byte;
  33.  xystar        : array[1..30] of char;
  34.  
  35. {$F+}
  36.  
  37. {****************************************************************************}
  38. {*                                                                          *}
  39. {*                            MouseinBox Procedure                          *}
  40. {*                                                                          *}
  41. {****************************************************************************}
  42. function mouseinbox(x1,y1,x2,y2,butt:word):boolean;
  43. var
  44.  a1, b1, c : word ;
  45. begin
  46.  ms_read(a1,b1,c);
  47.  a1:=(a1 div 8) + 1;
  48.  b1:=(b1 div 8) + 1;
  49.  if ((a1>=x1) and (a1<=x2) and (b1>=y1) and (b1<=y2) and (c=butt)) then
  50.     mouseinbox:=true
  51.  else
  52.     mouseinbox:=false;
  53. end;
  54.  
  55.  
  56.  
  57. {****************************************************************************}
  58. {*                                                                          *}
  59. {*                       Draw the stars on video page 1                     *}
  60. {*                                                                          *}
  61. {****************************************************************************}
  62. Procedure stars;
  63. begin
  64.  for loop:=1 to 30 do
  65.  begin
  66.     if ((random(80)<10) and (ord(xystar[loop])=15)) then
  67.     begin
  68.        xystar[loop]:=' ';
  69.     end;
  70.     if ((random(80)<5) and (xystar[loop]='∙')) then
  71.     begin
  72.        xystar[loop]:=chr(15);
  73.     end;
  74.     if ((random(80)<5) and (xystar[loop]='·')) then
  75.     begin
  76.        xystar[loop]:='∙';
  77.     end;
  78.     if ((random(80)<20) and (xystar[loop]=' ') and (x[loop]=0) and
  79. (y[loop]=0)) then
  80.     begin
  81.        x[loop]:=random(rows);
  82.        y[loop]:=random(columns);
  83.        xystar[loop]:='·';
  84.     end;
  85.  end;
  86.  for loop:=1 to 30 do
  87.  begin
  88.     r.ah:=$02;
  89.     r.bh:=$01;
  90.     r.dh:=x[loop];
  91.     r.dl:=y[loop];
  92.     intr($10,r);
  93.  
  94.     r.al:=ord(xystar[loop]);
  95.     r.ah:=$09;
  96.     r.bl:=7;
  97.     r.bh:=$01;
  98.     r.cx:=01;
  99.     intr($10,r);
  100.     if xystar[loop]=' ' then
  101.     begin
  102.        x[loop]:=0;
  103.        y[loop]:=0;
  104.     end;
  105.  end;
  106. end;
  107.  
  108. {****************************************************************************}
  109. {*                                                                          *}
  110. {*                       Initialize the stars Procedure                     *}
  111. {*                                                                          *}
  112. {****************************************************************************}
  113. Procedure starsinit;
  114. begin
  115.  for loop:=1 to 20 do xystar[loop]:=' ';
  116.  stars;
  117. end;
  118.  
  119. {****************************************************************************}
  120. {*                                                                          *}
  121. {*                        Check timer & blank the screen                    *}
  122. {*                                                                          *}
  123. {****************************************************************************}
  124. procedure blank; interrupt;
  125.                                             {This will be called every clock}
  126.                                             {tick by hardware interrupt $08.}
  127. begin
  128.  if screen_cond then stars;
  129.  asm cli end;
  130.  if blank_screen then inc(count);
  131.  if ((blank_screen_now) and (blank_screen)) then count:=5460;
  132.  if (count >= 5460) then                    {Ticks till Screen is blanked.  }
  133.                                             {Time is 18.2 TICKS/SEC, or 1092}
  134.                                             {Per minute, so                 }
  135.                                             {2 Mins = 2184,                 }
  136.                                             {3 Mins = 3276,                 }
  137.                                             {4 Mins = 4368,                 }
  138.                                             {5 Mins = 5460,                 }
  139.                                             {6 Mins = 6552,                 }
  140.                                             {7 Mins = 7644,                 }
  141.                                             {8 Mins = 8736,                 }
  142.                                             {9 Mins = 9828,                 }
  143.                                             {10 Mins = 10920,               }
  144.                                             {20 Mins = 21840,               }
  145.                                             {30 Mins = 32760, which is      }
  146.                                             {maximum limit of Integer       }
  147.                                             {variable used.                 }
  148.  begin
  149.     count       := 0;                       {Equality check and assignment  }
  150.                                             {faster than mod.               }
  151.     asm
  152.     mov AX,$02                              {Turn mouse off.                }
  153.     Int $33
  154.  
  155.     mov ah,$03                              {Turn the cursor off            }
  156.     mov bh,$00
  157.     int $10
  158.     or ch,$20
  159.     mov ah,$01
  160.     int $10
  161.  
  162.     mov ah,$05                              {Swaps to video page 1          }
  163.     mov al,$01
  164.     int $10
  165.     end;
  166.     if not screen_cond then starsinit;
  167.     screen_cond:=true;
  168.  end
  169.  else
  170.  begin
  171.     asm
  172.     mov ax,$0006                            {Check for Mouse Button press.  }
  173.     int $33
  174.     cmp bx,0
  175.     je @Test2
  176.     mov count,0
  177.  @test2:
  178.     mov ax,$000b                            {Check for mouse movement.      }
  179.     int $33
  180.     cmp cx,0
  181.     jz @test3
  182.     mov count,0
  183.  @test3:
  184.     cmp dx,0
  185.     jz @test4
  186.     mov count,0
  187.  @test4:
  188.     end;
  189.     if ((count=0) and (screen_cond)) then
  190.     begin
  191.        asm
  192.        mov ah,$05                           {Restore the first video page   }
  193.        mov al,$00;
  194.        int $10
  195.  
  196.        mov ah,$03                           {Turn the cursor on             }
  197.        mov bh,$00
  198.        int $10
  199.        and ch,$DF
  200.        mov ah,$01
  201.        int $10
  202.  
  203.        mov AX,$01                           {Turn mouse on                  }
  204.        Int $33
  205.        end;
  206.        screen_cond:=false;
  207.     end;
  208.  end;
  209.  asm
  210.  sti
  211.  pushf                                      {Push flags to set up for IRET. }
  212.  call OldInt1c;                             {Call old ISR entry point.      }
  213.  end;
  214. end;
  215.  
  216. {****************************************************************************}
  217. {*                                                                          *}
  218. {*                         New Interrupt 9 Procedure                        *}
  219. {*                                                                          *}
  220. {****************************************************************************}
  221. Procedure NewInt9; Interrupt;
  222. Begin
  223.  blank_screen_now:=false;
  224.  if (mouseinbox(80,1,80,1,0))=true then
  225.  asm
  226.  mov ax,0004
  227.  mov cx,630
  228.  mov dx,1
  229.  int $33
  230.  end;
  231.  count:=-1;                                 {Set to -1 because the blank    }
  232.                                             {procedure will increment before}
  233.                                             {it tests, so to get it to 0, it}
  234.                                             {must be set to -1.             }
  235.  asm
  236.  pushf                                      {Push flags to set up for IRET. }
  237.  call OldInt9;                              {Call old ISR entry point.      }
  238.  end;
  239. End;
  240.  
  241.  
  242. {****************************************************************************}
  243. {*                                                                          *}
  244. {*                  Reset everything at the end of the unit                 *}
  245. {*                                                                          *}
  246. {****************************************************************************}
  247. procedure ClockExitProc;
  248.                                             {This procedure is VERY         }
  249.                                             {important as you have hooked an}
  250.                                             {interrupt and therefore if this}
  251.                                             {is omitted when the unit is    }
  252.                                             {terminated your system will    }
  253.                                             {crash in an unpredictable and  }
  254.                                             {possibly damaging way.         }
  255. begin
  256.  ExitProc := ExitSave;
  257.  SetIntVec($1c,OldInt1c);                   {This "unhooks" the timer vector}
  258.  SetIntVec($09, Addr(OldInt9));             {This restores normal keyboard  }
  259.                                             {routines.                      }
  260.  
  261. end;
  262. {$F-}
  263.  
  264.  
  265. {****************************************************************************}
  266. {*                                                                          *}
  267. {*                        Unit Initializing procedure                       *}
  268. {*                                                                          *}
  269. {****************************************************************************}
  270. procedure Initialise;
  271. var
  272.  mode : byte absolute $40:$49;
  273. begin
  274.  asm
  275.  mov ah,$05                                 {Swap to video page 1, clear the}
  276.  mov al,$01                                 {screen by scrolling it, then   }
  277.  int $10                                    {return to video page 0.        }
  278.  
  279.  mov ah,$06
  280.  mov al,$00
  281.  mov bx,$00
  282.  int $10
  283.  
  284.  mov ah,$05                                 {Restore the first video page   }
  285.  mov al,$00
  286.  int $10
  287.  end;
  288.  GetIntVec($09, Addr(OldInt9));             {These two lines activate the   }
  289.  SetIntVec($09, Addr(NewInt9));             {new keyboard routine handler.  }
  290.  GetIntVec($1c,OldInt1c);                   {Get old timer vector & save it.}
  291.  ExitSave := ExitProc;                      {Save old exit procedure.       }
  292.  ExitProc := @ClockExitProc;                {Setup a new exit procedure.    }
  293.  SetIntVec($1c,@blank);                     {Hook the timer vector to the   }
  294.                                             {new procedure.                 }
  295. end;
  296.  
  297.  
  298. {****************************************************************************}
  299. {*                                                                          *}
  300. {*                           Main program starts here                       *}
  301. {*                                                                          *}
  302. {****************************************************************************}
  303. begin
  304.  Initialise;
  305.  Rows:=(mem[$0040:$0084]) + 1;              {Find the size from memory      }
  306.  Columns:=mem[$0040:$004a];
  307.  if rows   =0 then rows   :=25;             {If it could not find anything  }
  308.  if columns=0 then columns:=80;             {assume 25*80 mode.             }
  309. end.
  310.  
  311.